package com.xuecheng.content.controller;

import com.xuecheng.api.content.CourseAuditApi;
import com.xuecheng.api.content.model.dto.CourseBaseDTO;
import com.xuecheng.api.content.model.qo.QueryCourseModel;
import com.xuecheng.api.content.model.vo.CourseAuditVO;
import com.xuecheng.content.common.domain.page.PageRequestParams;
import com.xuecheng.content.common.domain.page.PageVO;
import com.xuecheng.content.convert.CourseBaseConvert;
import com.xuecheng.content.service.CourseBaseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class CourseAuditController implements CourseAuditApi {


    @Autowired
    private CourseBaseService courseBaseService;
    /*
    分页查询课程，运营查询所有
     */
    // 运营平台标识--可以查询所有教学机构的数据
    public static final Long OPERATION_FLAG = -99887799L;

    @Override
    @PostMapping("m/course/list")
    public PageVO queryCourseList(PageRequestParams params,@RequestBody QueryCourseModel model) {

        //调用service层课程查询的的方法，这里和查询每个机构的课程用的一个方法，
        PageVO pageVO = courseBaseService.queryCourseList(params, model, OPERATION_FLAG);

        return pageVO;
    }

    @Override
    @PostMapping("m/courseReview/approve")
    public void approveCourse(@RequestBody CourseAuditVO auditVO) {

        //需将vo转换为dto
        CourseBaseDTO dto = CourseBaseConvert.INSTANCE.vo2dto(auditVO);

        //调用service方法进行课程审核
        courseBaseService.approve(dto);

    }
}
